package com.wnhz.work.yz.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.wnhz.work.yz.BaseActivity;
import com.wnhz.work.yz.R;

public class AddPersonActivity extends BaseActivity implements View.OnClickListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add_person);
        initTitle();
        initView();
    }

    private EditText name, phone, email, wx_num, job;

    private void initView() {
        name = (EditText) findViewById(R.id.name);
        phone = (EditText) findViewById(R.id.phone);
        email = (EditText) findViewById(R.id.email);
        wx_num = (EditText) findViewById(R.id.wx_num);
        job = (EditText) findViewById(R.id.job);
    }

    private void initTitle() {
        TextView title = (TextView) findViewById(R.id.view_main_middle_title);
        title.setText("添加联系人");
        findViewById(R.id.btn_main_left).setOnClickListener(this);
        TextView submit = (TextView) findViewById(R.id.submit);
        submit.setText("保存");
        submit.setVisibility(View.VISIBLE);
        submit.setOnClickListener(this);
    }


//    public static boolean isMobileNO(String mobiles) {
//
//        Pattern p = Pattern.compile("/^0?(12[0-9]|13[0-9]|15[012356789]|17[013678]|18[0-9]|14[57])[0-9]{8}$/");
//
//        Matcher m = p.matcher(mobiles);
//        Log.e("----", m.matches() + "");
//        return m.matches();
//
//    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_main_left:
                finish();
                break;
            case R.id.submit:
                if (name.getText().toString().equals("")) {
                    MyToast("请填写名称");
                    return;
                }
                if (phone.length()!=11) {
                    MyToast("请填写正确的手机号");
                    return;
                }

                Intent intent = new Intent();
                intent.putExtra("name", name.getText().toString());
                intent.putExtra("phone", phone.getText().toString());
                intent.putExtra("email", email.getText().toString());
                intent.putExtra("job", job.getText().toString());
                intent.putExtra("wx_num", wx_num.getText().toString());
                setResult(RESULT_OK, intent);
                finish();
                break;
        }
    }
}
